using System;
using System.Collections.Generic;
namespace Week2
{
    internal class Week2Text
    {
        public abstract class Shape
        {
            public abstract double Area();
            public abstract bool IsAccepted();
            public abstract void say();
        }

        public class Rectangle : Shape
        {
            public double l;
            public double w;
            public Rectangle (double l,double w)
            {
                this.l = l;
                this.w = w;
            }
            public override double Area()
            {
                return l * w;
            }
            public override bool IsAccepted()
            {
                return (l > 0) && (w > 0);
            }
            public override void say()
            {
                Console.WriteLine("长方形，两边长为{0}，{1}", l, w);
            }
        }

        public class Square : Shape
        {
            public double a;
            public Square(double a)
            {
                this.a = a;
            }
            public override double Area()
            {
                return a * a;
            }
            public override bool IsAccepted()
            {
                return (a > 0);
            }
            public override void say()
            {
                Console.WriteLine("正方形，边长为{0}", a);
            }
        }

        public class Circle : Shape
        {
            public double r;
            public Circle(double r)
            {
                this.r = r;
            }
            public override double Area()
            {
                return Math.PI * r * r;
            }
            public override bool IsAccepted()
            {
                return (r > 0);
            }
            public override void say()
            {
                Console.WriteLine("圆形，半径为{0}", r);
            }
        }

        static void Main(string[] args)
        {
            List<Shape> l = new List<Shape>();
            Random random = new Random();  //随机生成，在System.Collections.Generic里

            for (int i = 0; i < 10; i++)
            {
                int type = random.Next(0, 3);
                switch (type)
                {
                    case 0:
                        l.Add(new Rectangle(random.NextDouble() * 10, random.NextDouble() * 10));
                        break;
                    case 1:
                        l.Add(new Square(random.NextDouble() * 10));//0.0-1.0随机数乘十
                        break;
                    case 2:
                        l.Add(new Circle(random.NextDouble() * 10));
                        break;
                }
            }
            double total = 0;
            foreach(var shape in l)
            {
                shape.say();
                total += shape.Area();
            }
            Console.WriteLine("总面积为{0}", total);
            Console.ReadKey();
        }
    }
}